/**
 * 
 */
package org.braketester.model.filters;

import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYSeries;

/**
 * @author LAP
 *
 */
public class RunnableSeriesAddValueFilter extends RunnableFilter {
	private XYSeries series;
	private Double addedItemsCount = (double) 0;
	private Thread filterThread;
	
	public RunnableSeriesAddValueFilter(XYSeries series) {
		if(series == null) throw new IllegalArgumentException("series must be not null");
		this.series = series;
		filterThread = new Thread(this);
	}
	
	public XYSeries getDataset() {
		return series;
	}
	
	public void setMaximumItemsCount(int count) {
		series.setMaximumItemCount(count);
	}
	
	/* (non-Javadoc)
	 * @see org.braketester.model.filters.RunnableFilter#doFilter(java.lang.Double)
	 */
	@Override
	protected Double doFilter(Double value) {
		series.add(new XYDataItem(value, addedItemsCount));
		addedItemsCount++;
		return value;
	}

	@Override
	public void start() {
		filterThread.start();
	}

}
